package cn.xlbweb.sso.util;

import cn.xlbweb.sso.constant.SsoProperties;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author: bobi
 * @date: 2019-03-09 16:57
 * @description:
 */
@Slf4j
public class UrlUtils {

    /**
     * http://sso.xlbweb.cn/verifyToken?token=xxx&clientUrl=http://127.0.0.1:8081&jessionId=7xxx2&projectId=xxx
     *
     * @param request
     * @param session
     * @param ssoProperties
     * @param token
     * @return
     */
    public static String getVerifyTokenUrl(HttpServletRequest request, HttpSession session, SsoProperties ssoProperties, String token) {
        String fullUrl = getFullUrl(request);
        return ssoProperties.getServerUrl() + "/verifyToken?token=" + token + "&clientUrl=" + fullUrl + "&jessionId=" + session.getId() + "&projectId=" + ssoProperties.getProjectId();
    }

    /**
     * http://127.0.0.1:8081
     *
     * @param request
     * @return
     */
    public static String getFullUrl(HttpServletRequest request) {
        return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
    }
}
